import re


class DurationMixIn(object):
    @staticmethod
    def process_duration(duration):
        if isinstance(duration, str):
            try:
                duration = "".join(duration.split())
                nums = re.findall(r"(\d+)", duration)  # 取出字符串中所有的数字
                num = max(int(i) for i in nums)
                dur = duration.split(str(num))[1]
                if len(dur) > 4:
                    dur = dur[:3]
                if "年" in dur:
                    num = int(num) * 365
                if "月" in dur:
                    num = int(num) * 30
                if "%" in dur:
                    num = 0
                number = num
            except:
                number = 0
            duration = number if number < 10000 else 0
        return duration
